package com.hunt.controller;

import com.hunt.model.entity.ExChangeDetail;
import com.hunt.model.entity.ExChangeLogInfo;
import com.hunt.model.entity.IndexNewsDetail;
import com.hunt.model.entity.IndexNewsInfo;
import com.hunt.service.ExChangeLogService;
import com.hunt.service.IndexNewsService;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(value = "手机app端,交易提示模块")
@Controller
@RequestMapping(path = "/app/exchangelog")
public class ExChangeLogController extends BaseController {

    @Autowired
    @Resource
    private ExChangeLogService exChangeLogService;
    @ApiOperation(value = "交易提示查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getExChangeLogInfo", method = RequestMethod.GET)
    public Result findIndexNewsInfo(@RequestParam(value = "time",required = false) String time,
                                    @RequestParam(value = "sizeUP", defaultValue = "10") Integer sizeUP) {
        List<ExChangeLogInfo> ExChangeLogInfolist=null;
        if(time==null||"null".equals(time)){
            Date da=new Date();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ExChangeLogInfolist = exChangeLogService.findExChangeLogInfoByPage(sdf.format(da), sizeUP);
        }
        else {
            ExChangeLogInfolist = exChangeLogService.findExChangeLogInfoByPage(time,sizeUP);
        }
        return Result.success(ExChangeLogInfolist);
    }

    @ApiOperation(value = "交易提示详情查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getExChangeDetail", method = RequestMethod.GET)
    public Result getIndexNewsDetail(@RequestParam(value = "datatime") String datatime) {
        ExChangeDetail detail =  exChangeLogService.findExChangeDetailBydatatime(datatime);
        return Result.success(detail);
    }
    @ApiOperation(value = "交易提示详情网页", httpMethod = "GET",produces = "text/html")
    @RequestMapping(value = "getExChangeDetailPage", method = RequestMethod.GET)
    public String getIndexNewsDetailPage(@RequestParam(value = "datatime") String datatime, Model model) {
        ExChangeDetail detail =  exChangeLogService.findExChangeDetailBydatatime(datatime);
        model.addAttribute("detail",detail);
        return "pc/oldpage";
    }
    @ApiOperation(value = "交易提示详情网页新", httpMethod = "GET",produces = "text/html")
    @RequestMapping(value = "getExChangeDetailNewPage", method = RequestMethod.GET)
    public String getExChangeDetailOldPage(@RequestParam(value = "datatime") String datatime, Model model) {
        ExChangeDetail detail =  exChangeLogService.findExChangeDetailBydatatime(datatime);
        model.addAttribute("detail",detail);
        return "pc/newpage";
    }
}